import 'dart:io';
import 'dart:convert';
import 'package:dio/dio.dart';

const AppBaseUrl1  = "https://api.zhuishushenqi.com";
const AppBaseUrl2  = "http://api.akousn.com";
enum HttpMethod{
  Get,
  Post,
}
class MyNetTool{
    static Future<Map> method(HttpMethod method,String url,String txCode,Map bodys,Map header) async{
    var stringUrl = url + txCode;
    switch (method){
      case HttpMethod.Get:{
        Response response = await Dio().get(stringUrl,queryParameters: bodys);
        var code = response.statusCode;
        if (code == 200){
          Map<String ,dynamic> object = json.decode(response.toString());
          return await object;
        }else{
          return {};
        }
      }break;
      case HttpMethod.Post:{
        var params = new Map<String, dynamic>.from(bodys);
        var headers = new Map<String, dynamic>.from(header);
        Dio dio = new Dio();
        BaseOptions options = BaseOptions(headers:headers);
        dio.options = options;
        Response response = await dio.post(stringUrl,data:params);
        var code = response.statusCode;
        if(code == 200){
          Map<String ,dynamic> object = json.decode(response.data.toString());
          return await object;
        }else{
          return {};
        }
      }break;

    }
  }
}